import Mock, { Random } from 'mockjs'

const roles = ['admin', 'editor', 'clear']

Mock.mock(`${process.env.VUE_APP_URL}/goods`, {
  name: '@cname',
  'age|10-100': 10,
  address: '@county(true)',
  age: 20,
  sex: '男',
  text: '@cparagraph(1, 3)'
})
// 用户登录
// http://localhost:8888/api/private/v1/login
console.log('url: ', `${process.env.VUE_APP_URL}/login`)
Mock.mock(`${process.env.VUE_APP_URL}/login`, 'post', req => {
  const reqBody = JSON.parse(req.body)
  let reData = {}
  if (roles.includes(reqBody.username)) {
    if (reqBody.username === 'clear') {
      reData = {
        code: 401,
        message: '登录信息已过期'
      }
    } else {
      reData = {
        code: 200,
        message: '登录成功',
        role: reqBody.username
      }
    }
  } else {
    reData = {
      code: 402,
      message: '用户名或密码错误'
    }
  }
  return reData
})

Mock.mock(`${process.env.VUE_APP_URL}/lineChart`, 'get', () => {
  function getArr() {
    const arr = []
    for (var i = 0; i < 7; i++) {
      arr[i] = Random.natural(10, 40)
    }
    return arr
  }
  return {
    // title: {
    //   text: '测试'
    // },
    grid: {
      left: 30,
      right: 20,
      bottom: 30,
      top: 40,
      width: 'auto'
    },
    tooltip: {},
    legend: {
      data: ['销量', '人数']
    },
    xAxis: {
      data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
    },
    yAxis: {},
    series: [
      {
        name: '销量',
        type: 'line',
        smooth: true,
        data: getArr()
      },
      {
        name: '人数',
        type: 'line',
        smooth: true,
        data: getArr()
      }
    ]

  }
})
Mock.mock(`${process.env.VUE_APP_URL}/barChart`, 'get', () => {
  function getArr() {
    const arr = []
    for (var i = 0; i < 7; i++) {
      arr[i] = Random.natural(10, 40)
    }
    return arr
  }
  return {
    // title: {
    //   text: '测试'
    // },
    tooltip: {},
    legend: {
      data: ['销量', '人数']
    },
    xAxis: {
      data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
    },
    yAxis: {},
    series: [
      {
        name: '销量',
        type: 'bar',
        smooth: true,
        data: getArr()
      },
      {
        name: '人数',
        type: 'bar',
        smooth: true,
        data: getArr()
      }
    ]

  }
})

Mock.mock(`${process.env.VUE_APP_URL}/pieChart`, 'get', () => {
  function getArr() {
    const arr = []
    for (var i = 0; i < 6; i++) {
      arr[i] = Random.natural(2000, 5000)
    }
    return arr
  }
  return {
    title: {
      text: '基础雷达图'
    },
    tooltip: {},
    legend: {
      data: ['预算分配', '实际开销']
    },
    radar: {
      // shape: 'circle',
      name: {
        textStyle: {
          color: '#fff',
          backgroundColor: '#999',
          borderRadius: 3,
          padding: [3, 5]
        }
      },
      indicator: [
        { name: '销售', max: 6500 },
        { name: '管理', max: 16000 },
        { name: '信息技术', max: 30000 },
        { name: '客服', max: 38000 },
        { name: '研发', max: 52000 },
        { name: '市场', max: 25000 }
      ]
    },
    series: [{
      name: '预算 vs 开销（Budget vs spending）',
      type: 'radar',
      // areaStyle: {normal: {}},
      data: [
        {
          value: getArr(),
          name: '预算分配（Allocated Budget）'
        },
        {
          value: getArr(),
          name: '实际开销（Actual Spending）'
        }
      ]
    }]
  }
})
